#ifndef MEMBERSCHEDULE_H
#define MEMBERSCHEDULE_H

#include "global.h"
#include "memberclass.h"
#include "mycombobox.h"
#include "mymembertable.h"

#include <QLabel>
#include <QList>
#include <QWidget>
#include <QJsonObject>
#include <QStackedWidget>
#include <QPushButton>
#include <QHBoxLayout>
#include <QVBoxLayout>

class MemberSchedule : public QWidget
{
    Q_OBJECT
public:
    explicit MemberSchedule(QWidget *parent = nullptr);
    MemberSchedule(QWidget *parent, QStackedWidget * pStackWidget);
    ~MemberSchedule(void);

private:
    /*tabel处理*/
    void initTabelWidget(void);
    template<class Type>
    void deleteBoxLayout(Type *t);
    void dataLoad(void);
    void transferJsonObjectToMemberClass(QJsonObject *pObj, QList<MemberClass*> *plist);
    void appendMemberList(QList<MemberClass*> & memberList, QJsonObject Obj);
    void updateMemberList(QList<MemberClass*> srcList, QList<MemberClass*> & dstList);
    int teacherForRookie(QList<MemberClass*> & memberList);
    int seleteTeacher(QString name, QList<MemberClass*> & memberList);
    void getTeacherName(QStringList & teacherList, QList<MemberClass*> memberList);
    int checkTeacherValid(QString name, QList<MemberClass*> memberList);

    /*tabel控件*/
    void initMemberSchedulePushButton(void);

    /*单元格及控件处理*/
    void setPushButtonDelete(int row, int column);
    void setPushButtonTeacherDelete(int row, int column);
    void initLevelComboBox(MyMemberTable *pTable, int index, int row);
#ifdef REQUIREMENT_ENABLE
    void initRequireComboBox(MyMemberTable *pTable, int index, int row);
#endif  // REQUIREMENT_ENABLE
    void setLevelToolTip(MyCombobox *pComBox, int level);
    void initTeacherDialogPushbutton(QDialog *pDialog);
    QPushButton * createDialogPushButton(QDialog *pDialog, QPoint point, QSize size,QString text);
    QLabel * createDialogLabel(QDialog *pDialog, QPoint point, QSize size, QString text, QFont font);
    void initDialogComboBox(QDialog *pDialog, MyCombobox * & pComBox, QPoint point, QSize size, QStringList strlist);

    /*文件处理*/
    void initJsonFile(void);
    void openJsonFile(QIODevice::OpenModeFlag flag);
    void readJsonData(QJsonObject &obj);
    void writeJsonData(QJsonObject &obj);
    void closeJsonFile(void);

signals:

public slots:
    void slot_memberScheduleAction_clicked(void);

private slots:
    void slot_btnAddMember_clicked(void);
    void slot_btnSave_clicked(void);
    void slot_btnCancel_clicked(void);
    void slot_tableWidget_cellChanged(int row, int column);
    void slot_pushButtonDelete_clicked(void);
    void slot_pushButtonTeacherDelete_clicked(void);
    void slot_LevelComboBox_currentIndexChanged(int index);
    void slot_teacherDialogBtn_clicked(void);

private:
    QWidget *myParent;
    QStackedWidget * pStackWidget;
    MyMemberTable *pTable;
    QDialog *pSelectTeacherDialog;
    MyCombobox *pSelectTeacherComBox;
    QLabel * pSelectTeacherLabel;
    QFile * jsonFile;
    QHBoxLayout *tableLayout;
    QHBoxLayout *btnLayout;
    QVBoxLayout *widgetLayout;
};

#endif // MEMBERSCHEDULE_H
